package com.cwnu.onlinemall.controller;

import com.cwnu.onlinemall.pojo.MallOrderlist;
import com.cwnu.onlinemall.pojo.ServerResult;
import com.cwnu.onlinemall.service.OrderListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin
@RestController
public class OrderListController {
    @Autowired
    OrderListService orderlistService;
    @RequestMapping("/orderlist/selectAll")
    public ServerResult selectAll(){
        if (orderlistService.SelectAll()!=null) {
            return new ServerResult(0, "查询成功", orderlistService.SelectAll());
        }else {
            return new ServerResult(1, "查询失败", null);
        }
    }


    @RequestMapping("/orderlist/selectById")
    public ServerResult selectById(Integer id){
        if (orderlistService.selectById(id)!=null) {
            return  new ServerResult(0,"查询成功",orderlistService.selectById(id));
        }else {
            return new ServerResult(1, "查询失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/orderlist/insert")
    public ServerResult insert(MallOrderlist mallOrderList){
        int row=orderlistService.insert(mallOrderList);
        if (row>=1) {
            return  new ServerResult(0,"插入成功",row);
        }else {
            return new ServerResult(1, "插入失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/orderlist/update")
    public  ServerResult update(MallOrderlist mallOrderList){
        int row=orderlistService.updateById(mallOrderList);
        if (row>=1) {
            return  new ServerResult(0,"更新成功",row);
        }else {
            return new ServerResult(1, "更新失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/orderlist/deleteById")
    public ServerResult delete(Integer id){
        int row=orderlistService.deleteById(id);
        if (row>=1) {
            return  new ServerResult(0,"删除成功",row);
        }else {
            return new ServerResult(1, "删除失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/orderlist/selectByCustomerId")
    public ServerResult selectByCustomerId(Integer id){
        if (orderlistService.selectByCustomerId(id)!=null) {
            return  new ServerResult(0,"查询成功",orderlistService.selectByCustomerId(id));
        }else {
            return new ServerResult(1, "查询失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/orderlist/selectByCommodityName")
    public ServerResult selectByCommodityName(String name){
        if (orderlistService.selectByCommodityName(name)!=null) {
            return  new ServerResult(0,"查询成功",orderlistService.selectByCommodityName(name));
        }else {
            return new ServerResult(1, "查询失败，可能输入字符有误", null);
        }
    }
    @RequestMapping("/orderlist/selectByCategoryName")
    public ServerResult selectByCategoryName(String categoryName){
        if (orderlistService.selectByCategoryName(categoryName).size()>=1) {
            return  new ServerResult(0,"查询成功",orderlistService.selectByCategoryName(categoryName));
        }else {
            return new ServerResult(1, "查询失败，可能输入字符有误", null);
        }
    }
}

